package com.jizi.machine.controller;

import com.jizi.machine.service.MachineService;
import com.jizi.machine.vo.RobotVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * description :
 * author :kang
 * create :2021-11-24 21:10:00
 */
@Slf4j
@RestController
@RequestMapping("/testmachine")
public class Testmachine {

    @Autowired
    private MachineService machineService;

    @Value("${webhook}")
    private String webhook;

    @ApiOperation("发送信息")
    @PostMapping(value = "/testRobot")
    public void testRobot(@RequestParam String robotVo) throws IOException {
        //VO这段可以写在业务逻辑层
        RobotVo vo = new RobotVo();
        //机器人地址
        vo.setWebhookAddress(webhook);
        //1.第一种情况：发送文本消息
        System.out.println(robotVo);
         vo.setContent(robotVo);
         List<String> memberList = new ArrayList<>();
         memberList.add("@all");
         vo.setMemberList(memberList);
         vo.setMsgType("text");

        // 2.第二种情况，发送图片消息
        // vo.setMsgType("image");
        // vo.setSavePath("C:/Users/Administrator/Desktop/吴彦祖.jpg");

        //3.第三种情况，发送机器人消息
//        vo.setMsgType("news");
//        vo.setTitle("test");
//        vo.setDescription("test");
//        vo.setUrl("url");
        // vo.setImageUrl("url")括号中的url是上传oss返回的路径
        //vo.setImageUrl("url");
        machineService.run(vo);
    }

    @ApiOperation("发送图片")
    @PostMapping(value = "/testUrl")
    public void robotVo(@RequestParam String testUrl) throws IOException {
        //VO这段可以写在业务逻辑层
        RobotVo vo = new RobotVo();
        //机器人地址
        vo.setWebhookAddress(webhook);
        //2.第二种情况，发送图片消息
        vo.setMsgType("image");
        vo.setSavePath(testUrl);
        machineService.run(vo);
    }


}
